package com.dkm.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
@Table(name = "module")
//@JsonIgnoreProperties(value = { "hibernateLazyInitializer"}) //忽略空属性
public class Module {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer module_id;
	private String module_name;
	
	private String path;
	private Integer weight;
	private String icon_class;
	
	private Integer parent_id;
	//子模块和父模块多对一关系
//	@ManyToOne(fetch = FetchType.EAGER)
//	@JoinColumn(name = "parent_id",referencedColumnName = "module_id")
//	private Module parentModule;
	//模块和角色多对多关系
	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "role_module",
			joinColumns = {@JoinColumn(name="module_id")},
			inverseJoinColumns = {@JoinColumn(name="role_id")}
	)
	private List<Role> roles;
	
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public Module() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public Module(Integer module_id, String module_name, String path, Integer weight, String icon_class) {
		super();
		this.module_id = module_id;
		this.module_name = module_name;
		this.path = path;
		this.weight = weight;
		this.icon_class = icon_class;
	}
	public Integer getModule_id() {
		return module_id;
	}
	public void setModule_id(Integer module_id) {
		this.module_id = module_id;
	}
	public String getModule_name() {
		return module_name;
	}
	public void setModule_name(String module_name) {
		this.module_name = module_name;
	}
	
	
	public Integer getParent_id() {
		return parent_id;
	}
	public void setParent_id(Integer parent_id) {
		this.parent_id = parent_id;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public Integer getWeight() {
		return weight;
	}
	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	public String getIcon_class() {
		return icon_class;
	}
	public void setIcon_class(String icon_class) {
		this.icon_class = icon_class;
	}
	@Override
	public String toString() {
		return "Module [module_id=" + module_id + ", module_name=" + module_name + ", path=" + path + ", weight="
				+ weight + ", icon_class=" + icon_class + "]";
	}
	
}
